<template>
  <div>
    <div class="searchForm">
      <el-form :inline="true" :model="r_search" class="demo-form-inline">
      <el-form-item >
        <el-input v-model="r_search.fileName" placeholder="请输入文件名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="r_search.uploadDate"
          type="date"
          placeholder="请选择上传日期"
          format="yyyy 年 MM 月 dd 日">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onSubmit">搜索</el-button>
      </el-form-item>
    </el-form>
</div>
    <el-table
      ref="multipleTable"
      :data="resourceData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        >
      </el-table-column>
      <el-table-column width="40" label="序号" type="index" show-overflow-tooltip></el-table-column>
      <el-table-column  prop="coursewareName"  label="文件名称" show-overflow-tooltip>
      </el-table-column>
      <el-table-column  prop="coursewareSize"  label="文件大小"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column  prop="coursewareAddtime"  label="上传日期" :formatter="dateFormat"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column  prop="studyResource.techer.teacherRealname"  label="上传人员"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column  label="操作"  show-overflow-tooltip>
        <template slot-scope="scope">
          <a :href="scope.row.coursewarePath"><el-button type="primary"  size="small">下载</el-button></a>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-button @click="toggleSelection()">取消选择</el-button>
    </div>
    <div class="block">
      <el-pagination
      @current-change="handleCurrentChange"
        :current-page.sync="pageIndex"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<style scoped="scope">
  .searchForm{
    text-align: center;
  }
</style>


<script>
  import {listResource} from '@/axios/api';
  import{ formatDate} from '@/common/js/date.js'
  export default {
    data() {
      return {
        r_search: {
          fileName: '',
          uploadDate: ''
        },
        resourceData: [],
        pageIndex:1,
        pageSize:10,
        total:10,
        multipleSelection: []
      }
    },
    methods: {
      //时间格式化
      dateFormat:(row, column) => {
        let date = row[column.property];
        if (date == undefined) {
          return "";
        }
        return formatDate(new Date(date), 'yyyy-MM-dd')
      },
      getResources:function(){
        let params = {
          pageIndex : this.pageIndex,
          coursewareName:this.r_search.fileName,
          coursewareAddtime: this.r_search.uploadDate
        }
        listResource(params).then( res => {
          this.pageSize = res.resData.pageSize;
          this.total = res.resData.total;
          this.resourceData = res.resData.list;
        })
      },

      onSubmit:function() {
        this.getResources() ;
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.listResource();
      },
      toggleSelection(rows) {
          this.$refs.multipleTable.clearSelection();
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    },
    mounted(){
      this.getResources();
    }
  }
</script>
